package com.yufubao.api.controller.management.authorization;


import com.yufubao.framework.annotation.SystemLog;
import com.yufubao.framework.result.PageUtils;
import com.yufubao.framework.result.ResponseResult;
import com.yufubao.model.pojo.management.authorization.RoleMenuEntity;
import com.yufubao.service.service.management.authorization.RoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 角色和菜单关联表
 *
 * @author zhangzhan
 * @email 52194440@qq.com
 * @date 2024-09-04 15:00:26
 */
@Api("角色和菜单关联表")
@RestController
@RequestMapping("/applet/management/rolemenu")
public class RoleMenuController {
    @Autowired
    private RoleMenuService roleMenuService;

    /**
     * 列表
     */
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ApiOperation(value = "角色和菜单关联表列表")
    @SystemLog(info = "角色和菜单关联表列表")
    public ResponseResult list(@RequestBody Map<String, Object> params){
        PageUtils page = roleMenuService.queryPage(params);

        return ResponseResult.okResultPage("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping(value = "/info/{roleId}",method = RequestMethod.GET)
    @ApiOperation(value = "角色和菜单关联表信息")
    @SystemLog(info = "角色和菜单关联表信息")
    public ResponseResult info(@PathVariable("roleId") Long roleId){
		RoleMenuEntity roleMenu = roleMenuService.getById(roleId);

        return ResponseResult.okResultPage("RoleMenu", roleMenu);
    }

    /**
     * 保存
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ApiOperation(value = "角色和菜单关联表保存")
    @SystemLog(info = "角色和菜单关联表保存")
    public ResponseResult save(@RequestBody RoleMenuEntity roleMenu){
		roleMenuService.save(roleMenu);

        return ResponseResult.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    @ApiOperation(value = "角色和菜单关联表修改")
    @SystemLog(info = "角色和菜单关联表修改")
    public ResponseResult update(@RequestBody RoleMenuEntity roleMenu){
		roleMenuService.updateById(roleMenu);

        return ResponseResult.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    @ApiOperation(value = "角色和菜单关联表删除")
    @SystemLog(info = "角色和菜单关联表删除")
    public ResponseResult delete(@RequestBody Long[] roleIds){
		roleMenuService.removeByIds(Arrays.asList(roleIds));

        return ResponseResult.ok();
    }

}
